{extend name="public/base"}

{block name="title"}
收货地址
{/block}

{block name="style"}
{css href="/static/wechat/css/index.css" /}
{css href="/static/wechat/popo1/css/store.css" /}
<style>
    .add_list1 label{
        width: auto;
        border: none;
    }

    .add_list1 label.checked{
         color: red;
     }

    .add_list1 label i{
        display: block;
        width: 1rem;
        height: 1rem;
        float: left;
        border: 1px solid #eee;
        border-radius: 50%;
        margin-right: 5px;
    }
</style>
{/block}

{block name="body"}
<div class="pageControl1 startShop bg-f8">
    <div class="nav">
        <div class="msui_navTop">
            <a class="msui_navTop-back" href="javascript:history.back();"><i class="micon-back_ff6"></i></a>
            <h1 class="msui_navTop-title">地址管理</h1>
            <a class="msui_navTop-icon cl-fc4" href="{:url('save_address')}">
                添加
            </a>
        </div>
    </div>
    <div class="add_content">
        {empty name="data"}
        <p style="margin: 2rem 0; text-align: center;">无收货地址</p>
        {else /}
        {volist name="data" id="vo"}
        <div class="weui-cells add_list">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <p>{$vo.linkman}</p>
                    <p class="cl-9999">{$vo.province}{$vo.city}{$vo.area}{$vo.street}{$vo.address}</p>
                </div>
                <div class="weui-cell__ft o_cell">
                    <p class="cl-3333">{$vo.phone}</p>
                </div>
            </div>
            <div class="weui-cell add_list1">
                <div class="weui-cell__bd">
                    {eq name="vo.is_default" value="1"}
                    <p class="cl-9999">
                        <label class="checked"  data-id="{$vo.id}" >
                            <i></i> <span>默认地址</span>
                        </label>
                    </p>
                    {else /}
                    <p class="cl-9999">
                        <label data-id="{$vo.id}" >
                            <i></i> <span>设为默认地址</span>
                        </label>
                    </p>
                    {/eq}
                </div>
                <a href="{:url('save_address', ['id'=> $vo['id']])}" class="weui-cell__ft">编辑</a>
                <a href="javascript:;" data-id="{$vo.id}" class="weui-cell__ft delete">删除</a>
            </div>
        </div>
        {/volist}
        {/empty}
    </div>

</div>

<!-- loading toast -->
<div id="loadingToast" style="display:none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast" style="opacity: 1; visibility: visible;">
        <i class="weui-loading weui-icon_toast"></i>
        <p class="weui-toast__content">加载中...</p>
    </div>
</div>

{/block}


{block name="javascript"}
{js href="/static/wechat/popo1/js/shop.js" /}
<script>
    $(function () {
        $('.list_mo').click(function(e){
            e.preventDefault();
            var listId=$(this).attr('href');
            $('label').removeAttr('class');
            $("#"+listId).next().attr('class', 'checked');
        });

        $('.add_list1 label').click(function(){
            var _this = $(this);
            if(_this.hasClass('checked')) {
                return false;
            }
            if(!confirm('确定设为默认收获地址？')) {
                return false;
            }
            $('#loadingToast').fadeIn();
            var id = _this.data('id');
            $.get('{:url("save_default_address")}', {id : id}, function (msg) {
                if (msg.code == 200) {
                    alert('设置成功！！');
                    window.location.reload();
                } else{
                    var code = msg.code;
                    $.alert(error_code[code]);
                }
                $('#loadingToast').fadeOut();
            }, 'json');
        });

       $(".delete").click(function () {
           if (!confirm('确定删除售后地址？')) {
               return false;
           }
           $('#loadingToast').fadeIn();
           var _this = $(this);
           var id = _this.data('id');
           $.get('{:url("delete_address")}', {id : id}, function (msg) {
               if (msg.code == 200) {
                   alert('删除成功！！');
                   window.location.reload();
               } else{
                   var code = msg.code;
                   $.alert(error_code[code]);
               }
               $('#loadingToast').fadeOut();
           }, 'json');
       }); 
    });
</script>
{/block}